package com.cmos.um.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.cmos.um.iservice.IAgentSV;
import com.cmos.um.utils.Result;
import com.cmos.um.utils.ResultUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 坐席相关接口
 */
@RestController
@RequestMapping("/ngocadapter/ws/campaignService")
public class AgentController {
    @Reference
    private IAgentSV iAgentSV;

    /**
     * 查询任务坐席状态接口
     * @param params
     * @return
     */
    @PostMapping("/taskAgentState")
    public Result taskAgentState(@RequestBody JSONObject params) {
        if (!params.containsKey("params") && !params.getJSONObject("params").containsKey("serviceId")) {
            return ResultUtil.error("-9999", "入参不符合规范");
        }
        if (params.getJSONObject("params").getString("serviceId").length() != 16) {
            return ResultUtil.error("-9999", "任务号必须为16位！");
        }
        return iAgentSV.taskAgentState(params);
    }

    /**
     * 向所有的cti新增坐席
     * @param params
     * @return
     */
    @PostMapping("/agent")
    public Result addAgent(@RequestBody JSONObject params) {
        if (!params.containsKey("params")) {
            return ResultUtil.error("-9999", "入参不符合规范");
        }
        return iAgentSV.addAgent(params);
    }
}
